package com.atguigu.condition;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author : zjj
 * @date : 2021/9/23 14:55
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    /**
     *
     * @param importingClassMetadata    当前类的注解信息
     * @param registry                  bean注册信息，所有已经注册Bean的信息都会放到这里面
     */
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean containBlue = registry.containsBeanDefinition("com.atguigu.bean.Blue");

        boolean containRed = registry.containsBeanDefinition("com.atguigu.bean.Red");
        if(containRed && containBlue){
            RootBeanDefinition beanDefinition = new RootBeanDefinition("com.atguigu.bean.RainBow");
            registry.registerBeanDefinition("rainBow",beanDefinition);
        }

    }
}
